package com.pdsu.graduation_design.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.component.RoundCornerImageView;
import com.pdsu.graduation_design.domain.CommodityType;
import com.squareup.picasso.Picasso;

import java.sql.Connection;
import java.util.List;

public class MainGridViewAdapter extends BaseAdapter {


    /**
     * 将数据写入gridview
     * @return
     */
    List<CommodityType> types;

    private int[] images={R.drawable.potato,R.drawable.tomtato,R.drawable.cucumber,R.drawable.potato,R.drawable.tomtato,R.drawable.cucumber};
    private String[] titles={"potato","tomato","cucumber","potato","tomato","cucumber"};


    public MainGridViewAdapter(List<CommodityType> types, Context context) {
        this.types = types;
        this.context = context;
    }

    public MainGridViewAdapter(Context context) {

        this.context = context;
    }

    private Context context;
    private RoundCornerImageView imageView;
    private TextView textView;

    @Override
    public int getCount() {
        return types.size();
    }

    @Override
    public Object getItem(int position) {
        return types.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view=View.inflate(context, R.layout.main_gridview_item,null);


        textView=view.findViewById(R.id.main_gridview_title);
        imageView=view.findViewById(R.id.main_gridview_image);
/***
 *
 *
 * ...
 */
        // agricultures.add(new Agriculture(1,1,"@",R.drawable.potato,));

        textView.setText(types.get(position).getType());
        Picasso.with(context).load(types.get(position).getImage()).into(imageView);
        return view;
    }
}
